public class BabylonianSqrt {
    public static double sqrt(long n) {
        double lastGuess = 1.0;
        double nextGuess;
        do {
            nextGuess = (lastGuess + n / lastGuess) / 2.0;
            if (Math.abs(nextGuess - lastGuess) < 0.0001) {
                break;
            }
            lastGuess = nextGuess;
        } while (true);
        return nextGuess;
    }

    public static void main(String[] args) {
        System.out.println("Square root of 16: " + sqrt(16));
        System.out.println("Square root of 25: " + sqrt(25));
        System.out.println("Square root of 2: " + sqrt(2));
    }
}